import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state:{
		loginState: uni.getStorageSync('loginState')=== 'ok' ? true: false,
		userInfo: uni.getStorageSync('userInfo') ? JSON.parse(uni.getStorageSync('payload')) : {
			name: '未知用户',
			liked: 0,
			avatar: '/static/nopic.png',
			commented: 0
		},
	},
	getters:{
		
	},
	mutations:{
		userLogin(state, payload) {
			state.loginState = true
			state.userInfo =  payload
			uni.setStorageSync( 'loginState', ok)
			uni.setStorageSync('userInfo',JSON.stringify(payload))
		},
		userLogout(state){
			loginState = false,
			userInfo = {
				name: '未知用户',
				liked: 0,
				avatar: '/static/nopic.png',
				commented: 0
			}
			uni.clearStorage('loginState')
			uni.clearStorage('userInfo')
			uni.clearStorage('token')
		}
	},
	actions: {
		userLoginAction(context, payload){
			context.commit('userLogin', payload)
		},
		userLogoutAction(context){
			context.commit('userLogout')
		}
	}
})
export default store 